<!--
# coding=UTF-8
# Copyright (c) 2025 Bird Software Solutions Ltd
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#    Neil Mackenzie - initial API and implementation
#    Benjamin Arfa - improvements
#
-->
{% extends "pybirdai/workflow/base.html" %}

{% block breadcrumb_items %}
<span class="breadcrumb-separator">›</span>
<a href="{% url 'pybirdai:workflow_task' task_number=1 operation='do' %}">Task 1: SMCubes Core Creation</a>
<span class="breadcrumb-separator">›</span>
<span>Review</span>
{% endblock %}

{% block workflow_content %}
<div class="task-content">
    <h1>Task 1: SMCubes Core Creation - Review</h1>

    <h2>SMCubes Core Creation Process</h2>

    <div class="process-overview">
        <div class="process-step">
            <div class="step-icon">1</div>
            <div class="step-content">
                <h3>Database Preparation</h3>
                <p>Clear existing database content for fresh import</p>
                <ul>
                    <li>Remove existing data structures</li>
                    <li>Reset database state</li>
                    <li>Prepare for new imports</li>
                </ul>
                {% if execution_data.database_deleted %}
                <span class="status-badge completed">✓ Completed</span>
                {% else %}
                <span class="status-badge pending">⏳ Pending</span>
                {% endif %}
            </div>
        </div>

        <div class="process-step">
            <div class="step-icon">2</div>
            <div class="step-content">
                <h3>Input Model Import</h3>
                <p>Import LDM/EIL model and create cube structures</p>
                <ul>
                    <li>Parse LDM/EIL model files</li>
                    <li>Generate variables and domains</li>
                    <li>Create cube structures</li>

                </ul>
                {% if execution_data.input_model_imported %}
                <span class="status-badge completed">
                    ✓ Completed ({{ execution_data.cubes_created|default:"50+" }} cubes)
                </span>
                {% else %}
                <span class="status-badge pending">⏳ Pending</span>
                {% endif %}
            </div>
        </div>

        <div class="process-step">
            <div class="step-icon">3</div>
            <div class="step-content">
                <h3>Report Templates Creation</h3>
                <p>Generate report template structures from definitions</p>
                <ul>
                    <li>Parse template definitions</li>
                    <li>Create template structures</li>
                    <li>Link templates to cubes</li>
                </ul>
                {% if execution_data.report_templates_created %}
                <span class="status-badge completed">
                    ✓ Completed ({{ execution_data.templates_created|default:"100+" }} templates)
                </span>
                {% else %}
                <span class="status-badge pending">⏳ Pending</span>
                {% endif %}
            </div>
        </div>

        <div class="process-step">
            <div class="step-icon">4</div>
            <div class="step-content">
                <h3>Hierarchy Import</h3>
                <p>Convert and import LDM/EIL hierarchical structures</p>
                <ul>
                    <li>Import hierarchy data</li>
                </ul>
                {% if execution_data.hierarchy_analysis_imported %}
                <span class="status-badge completed">
                    ✓ Completed ({{ execution_data.hierarchies_imported|default:"200+" }} hierarchies)
                </span>
                {% else %}
                <span class="status-badge pending">⏳ Pending</span>
                {% endif %}
            </div>
        </div>

        <div class="process-step">
            <div class="step-icon">5</div>
            <div class="step-content">
                <h3>Semantic Integration Processing</h3>
                <p>Create semantic mappings and integration structures</p>
                <ul>
                    <li>Process semantic mappings</li>

                    <li>Validate mappings</li>
                </ul>
                {% if execution_data.semantic_integrations_processed %}
                <span class="status-badge completed">
                    ✓ Completed ({{ execution_data.semantic_integrations|default:"150+" }} integrations)
                </span>
                {% else %}
                <span class="status-badge pending">⏳ Pending</span>
                {% endif %}
            </div>
        </div>
    </div>

    <h2>SMCubes Core Creation Summary</h2>

    <div class="summary-grid">
        <div class="summary-card">
            <h3>Creation Status</h3>
            <div class="status-indicator success">
                <span class="status-icon">✓</span>
                <span class="status-text">SMCubes Core Created Successfully</span>
            </div>
            <dl>
                <dt>Cube Structures:</dt>
                <dd>{{ execution_data.cubes_created|default:"50+" }} cubes</dd>

                <dt>Hierarchies Imported:</dt>
                <dd>{{ execution_data.hierarchies_imported|default:"200+" }} hierarchies</dd>

                <dt>Report Templates:</dt>
                <dd>{{ execution_data.templates_created|default:"100+" }} templates</dd>

                <dt>Semantic Integrations:</dt>
                <dd>{{ execution_data.semantic_integrations|default:"150+" }} integrations</dd>
            </dl>
        </div>

        <div class="summary-card">
            <h3>Data Quality</h3>
            <div class="status-indicator success">
                <span class="status-icon">📊</span>
                <span class="status-text">Data Quality Metrics</span>
            </div>
            <dl>
                <dt>Variables Processed:</dt>
                <dd>{{ execution_data.variables_processed|default:"1,200+" }} variables</dd>

                <dt>Members Created:</dt>
                <dd>{{ execution_data.members_created|default:"5,000+" }} members</dd>

                <dt>Missing Members:</dt>
                <dd class="{% if execution_data.missing_members > 0 %}text-warning{% else %}text-success{% endif %}">
                    {{ execution_data.missing_members|default:"0" }} missing
                </dd>

                <dt>Data Completeness:</dt>
                <dd class="text-success">{{ execution_data.completeness_percentage|default:"98%" }}</dd>
            </dl>
        </div>
    </div>


    <h2>SMCubes Core Review Actions</h2>

    <div class="metadata-review-section">
        <div class="review-category">
            <h3>Hierarchy Review</h3>
            <p>Review and validate the hierarchy structures created during import:</p>
            <div class="review-links">
                <a href="{% url 'pybirdai:missing_children' %}" target="_blank" class="review-link">
                    <span class="link-icon">📊</span>
                    <span class="link-text">Show Missing Children in Hierarchies</span>
                </a>
                <a href="{% url 'pybirdai:missing_members' %}" target="_blank" class="review-link">
                    <span class="link-icon">📋</span>
                    <span class="link-text">Show Missing Leaf Members in Hierarchies</span>
                </a>
                <a href="{% url 'pybirdai:member_hierarchy_editor' %}" target="_blank" class="review-link">
                    <span class="link-icon">⚙️</span>
                    <span class="link-text">Edit and visualize Member Hierarchy</span>
                </a>
            </div>
        </div>

        <div class="review-category">
            <h3>Semantic Integration Review</h3>
            <p>Review and validate the semantic mappings and integrations:</p>
            <div class="review-links">
                <a href="{% url 'pybirdai:mappings_missing_members' %}" target="_blank" class="review-link">
                    <span class="link-icon">️️️⚠️</span>
                    <span class="link-text">Show Missing Members in Mappings</span>
                </a>
                <a href="{% url 'pybirdai:mappings_missing_variables' %}" target="_blank" class="review-link">
                    <span class="link-icon">⚠️</span>
                    <span class="link-text">Show Missing Variables in Mappings</span>
                </a>
                <a href="{% url 'pybirdai:mappings_warnings_summary' %}" target="_blank" class="review-link">
                    <span class="link-icon">📋</span>
                    <span class="link-text">Show Warnings Summary</span>
                </a>
                <a href="{% url 'pybirdai:edit_variable_mappings' %}" target="_blank" class="review-link">
                    <span class="link-icon">✏️</span>
                    <span class="link-text">Edit Variable Mappings</span>
                </a>
                <a href="{% url 'pybirdai:edit_variable_mapping_items' %}" target="_blank" class="review-link">
                    <span class="link-icon">✏️</span>
                    <span class="link-text">Edit Variable Mapping Items</span>
                </a>
                <a href="{% url 'pybirdai:edit_member_mappings' %}" target="_blank" class="review-link">
                    <span class="link-icon">✏️</span>
                    <span class="link-text">Edit Member Mappings</span>
                </a>
                <a href="{% url 'pybirdai:edit_member_mapping_items' %}" target="_blank" class="review-link">
                    <span class="link-icon">✏️</span>
                    <span class="link-text">Edit Member Mapping Items</span>

                </a>
                <a href="{% url 'pybirdai:edit_mapping_to_cubes' %}" target="_blank" class="review-link">
                    <span class="link-icon">✏️</span>
                    <span class="link-text">Edit Mapping to Cubes</span>
                </a>
                <a href="{% url 'pybirdai:edit_mapping_definitions' %}" target="_blank" class="review-link">
                    <span class="link-icon">✏️</span>
                    <span class="link-text">Edit Mapping Definitions</span>
                </a>
                <a href="{% url 'pybirdai:return_semantic_integration_menu' %}" target="_blank" class="review-link">
                    <span class="link-icon">⚙️</span>
                    <span class="link-text">Mappings Editor</span>
                </a>
                <a href="{% url 'pybirdai:view_member_mapping_items_by_row' %}" target="_blank" class="review-link">
                    <span class="link-icon">🔍</span>
                    <span class="link-text">View Member Mapping Items By Row</span>
                </a>
                <a href="{% url 'pybirdai:run_delete_mappings' %}" target="_blank" class="review-link">
                    <span class="link-icon">❌</span>
                    <span class="link-text">Delete Semantic Integrations</span>
                </a>
            </div>
        </div>
    </div>

    <div class="form-actions" style="margin-top: 30px;">
        <!-- <form method="post" style="display: inline;">
            {% csrf_token %}
            <button type="submit" name="mark_reviewed" class="btn btn-success">Mark as Reviewed</button>
        </form>
        <a href="{% url 'pybirdai:workflow_task' task_number=3 operation='compare' %}" class="btn btn-primary">Go to Compare</a> -->
        <a href="{% url 'pybirdai:workflow_task' task_number=2 operation='do' %}" class="operation-btn btn-primary">Proceed to Task 2</a>
        <a href="{% url 'pybirdai:workflow_dashboard' %}" class="operation-btn btn-secondary">Back to Dashboard</a>
    </div>

</div>

<style>
.process-overview {
    margin: 20px 0;
}

.process-step {
    display: flex;
    align-items: flex-start;
    margin-bottom: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.step-icon {
    width: 40px;
    height: 40px;
    background: #0d6efd;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    margin-right: 20px;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
}

.step-content h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #495057;
}

.step-content ul {
    margin: 10px 0;
    padding-left: 20px;
    color: #6c757d;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    margin-top: 10px;
}

.status-badge.completed {
    background-color: #d1e7dd;
    color: #0f5132;
    border: 1px solid #a3cfbb;
}

.status-badge.pending {
    background-color: #fff3cd;
    color: #664d03;
    border: 1px solid #ffecb5;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.summary-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.summary-card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #495057;
}

.summary-card dl {
    margin: 0;
}

.summary-card dt {
    font-weight: bold;
    margin-top: 10px;
}

.summary-card dd {
    margin-left: 0;
    margin-bottom: 10px;
}

.metadata-review-section {
    margin-bottom: 30px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.review-category {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
}

.review-category h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #495057;
    border-bottom: 2px solid #0d6efd;
    padding-bottom: 8px;
}

.review-category p {
    margin-bottom: 15px;
    color: #6c757d;
}

.review-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.review-link {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    text-decoration: none;
    color: #495057;
    transition: all 0.2s ease;
}

.review-link:hover {
    background: #e9ecef;
    border-color: #0d6efd;
    color: #0d6efd;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.link-icon {
    margin-right: 10px;
    font-size: 16px;
}

.link-text {
    font-weight: 500;
}

.status-indicator {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.status-indicator.success {
    background: #d4edda;
    color: #155724;
}

.status-icon {
    margin-right: 10px;
    font-size: 18px;
}

.status-text {
    font-weight: 500;
}

.text-warning {
    color: #856404;
}

.text-success {
    color: #155724;
}


.alert {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.alert-warning {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.progress {
    height: 25px;
    margin-top: 10px;
}

.substep-btn {
    margin-top: 10px;
    margin-left: 10px;
}
</style>
{% endblock %}
